package com.hfh.jdbc;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author hfh
 * @Date 2022 09 20 19 48
 **/
public class DruidDemo {
    public static void main(String[] args) throws IOException, SQLException {
        Properties pros = new Properties();
        InputStream is = DruidDemo.class.getClassLoader()
                .getResourceAsStream("jdbc.properties");
        pros.load(is);

        DruidDataSource dataSource = new DruidDataSource();

        dataSource.setUrl(pros.getProperty("url"));
        dataSource.setUsername(pros.getProperty("user"));
        dataSource.setPassword(pros.getProperty("password"));
        dataSource.setInitialSize(Integer.valueOf(pros.getProperty("initialSize")));
        dataSource.setMaxActive(Integer.valueOf(pros.getProperty("maxActive")));
        dataSource.setMinIdle(Integer.valueOf(pros.getProperty("minldle")));
        dataSource.setMaxWait(Integer.valueOf(pros.getProperty("maxWait")));

        DruidPooledConnection con = dataSource.getConnection();
        System.out.println(con);


    }
}
